package com.rawm.gen.common;

import com.rawm.gen.dbutil.DBUtils;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 表结构常量
 *
 * @author hxy
 * @since 1.0.0
 */
public class Constant {

    public final static String DOT = ".";
    /**
     * 工程的名称
     */
    public static final String PROJECT_PATH = "/generate-code";
    /**
     * 列名称
     */
    public static final String COLUMN_NAME = "COLUMN_NAME";
    /**
     * 主工程文件
     */
    public final static String SRC_PATH = "/src/" + File.separator;
    /**
     * java文件的后缀
     */
    public static final String JAVA_SUFFIX = ".java";
    /**
     * xml文件的后缀
     */
    public static final String MAPPINGS_SUFFIX = ".xml";
    /**
     * 列的类型名称
     */
    public static final String TYPE_NAME = "TYPE_NAME";
    /**
     * 表的注释信息
     */
    public static final String REMARKS = "REMARKS";

    /**
     * 连接的url
     */
    public static String URL;
    /**
     * 数据库账户
     */
    public static String USER;
    /**
     * 数据库密码
     */
    public static String PASSWORD;
    /**
     * Mysql驱动类
     */
    public static String DRIVER;
    /**
     * 包前缀
     */
    public static String PKG_PREFIX;
    /**
     * 实体包后缀
     */
    public static String PKG_ENTITY;
    /**
     * dto包后缀
     */
    public static String PKG_DTO;
    /**
     * vo包后缀
     */
    public static String PKG_VO;
    /**
     * dto包后缀
     */
    public static String PKG_CONTROLLER;
    /**
     * struct包后缀
     */
    public static String PKG_STRUCT;
    /**
     * dao包后缀
     */
    public static String PKG_DAO;
    /**
     * 服务包后缀
     */
    public static String PKG_SERVICE;
    /**
     * 服务实现层
     */
    public static String PKG_SERVICE_IMPL;


    static {
        try {
            InputStream stream = DBUtils.class.getClassLoader().getResourceAsStream("mybatis.properties");
            Properties properties = new Properties();
            properties.load(stream);
            DRIVER = properties.getProperty("jdbc_driver");
            URL = properties.getProperty("jdbc_url");
            USER = properties.getProperty("jdbc_user");
            PASSWORD = properties.getProperty("jdbc_password");
            PKG_PREFIX = properties.getProperty("pkg_prefix");
            PKG_ENTITY = DOT + properties.getProperty("pkg_entity");
            PKG_DTO = DOT + properties.getProperty("pkg_dto");
            PKG_VO = DOT + properties.getProperty("pkg_vo");
            PKG_CONTROLLER = DOT + properties.getProperty("pkg_controller");
            PKG_DAO = DOT + properties.getProperty("pkg_dao");
            PKG_SERVICE = DOT + properties.getProperty("pkg_service");
            PKG_SERVICE_IMPL = DOT + properties.getProperty("pkg_service_impl");
            PKG_STRUCT = DOT + properties.getProperty("pkg_struct");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
